package com.lagou.controller;

import com.lagou.pojo.Goods;
import com.lagou.pojo.Order;
import com.lagou.service.OrderService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 *
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/findById/{id}")
    public Order findOrderById(@PathVariable Integer id){
        Order orderById = orderService.findOrderById(id);
        return orderById;

    }

    @RequestMapping("/findByPage")
    public Map<List, Integer> selectOrderByPage(Integer page,String createTimemin,String createTimemax,String status){

        Map<List, Integer> listIntegerMap = orderService.selectOrderByPage(page, createTimemin, createTimemax, status);
        return listIntegerMap;

    }

    @HystrixCommand(
            threadPoolKey = "getOrderServerPort2",
            commandProperties={
                    //设置请求超时时间5秒
                    @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "5000")

            },
            //设置回退的方法
            fallbackMethod = "fallBack"
    )
    @RequestMapping("/findGoodsById/{id}")
    public Goods selectGoodsListById(@PathVariable Integer id){
        Goods goods = orderService.selectGoodsListById(id);
        return goods;

    }

    public Goods fallBack(Integer id){
        System.out.println(id);
        return null;
    }

}
